<template>
  <div class="app-container">
    <el-form :model="queryParams" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item   label="学院" prop="xyId">
        <el-select v-model="queryParams.xyId" @change="handlelistPronj" placeholder="请选择" clearable>
          <el-option
            v-for="item in proxyList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="queryParams.xyId!=null" label="年级" prop="njId">
        <el-select v-model="queryParams.njId" @change="handlelistProzy" placeholder="请选择" clearable>
          <el-option
            v-for="item in pronjList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="queryParams.njId!=null" label="专业" prop="zyId">
        <el-select v-model="queryParams.zyId"  @change="handlelistProbj" placeholder="请选择" clearable>
          <el-option
            v-for="item in prozyList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="queryParams.zyId!=null" label="班级" prop="clId">
        <el-select v-model="queryParams.clId" placeholder="请选择" clearable>
          <el-option
            v-for="item in probjList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>



      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button size="mini" type="warning" @click="clearCron">重置</el-button>
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="pronoticeList">
      <el-table-column label="编号" align="center" prop="number" />
      <el-table-column label="学院" align="center" prop="xyName" />
      <el-table-column label="年级" align="center" prop="njName" />
      <el-table-column label="专业" align="center" prop="zyName" />
      <el-table-column label="班级名称" align="center" prop="name" />
      <!-- <el-table-column label="指导教师" align="center" prop="jsName" /> -->
      <el-table-column label="总进度" align="center" prop="jdCount" />
<!--      <el-table-column label="基础劳动进度" align="center" prop="name" />-->
<!--      <el-table-column label="劳动总结报告进度" align="center" prop="name" />-->
<!--      <el-table-column label="社会公益劳动进度" align="center" prop="name" />-->
<!--      <el-table-column label="劳动成果进度" align="center" prop="content" />-->
<!--      <el-table-column label="理论课程进度" align="center" prop="content" />-->
      <el-table-column label="督促" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="danger"
            round
            @click="handleUpdate(scope.row)"
            v-hasPermi="['project:prouseryjdc:add']"
          >督促</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加督促管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="督促内容" prop="content">
          <el-input v-model="form.content" placeholder="请输入督促内容"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定 督 促</el-button>
        <el-button @click="cancel">取 消 督 促</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProuseryjdc,createDc } from "@/api/project/prouseryjdc";
import {listProbj, listPronj, listProxy, listProzy} from "@/api/project/prouser";


export default {
  name: "Pronotice",
  data() {
    return {
      // 遮罩层
      loading: true,

      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 督促数据
      pronoticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        xyId:null,
        njId:null,
        zyId:null,
        clId:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        content:[{ required: true, message: "请输入督促内容", trigger: "blur" }]
      },
      //督促内容
      content:'',

      prozyList:[],
      proxyList:[],
      proxxList:[],
      pronjList:[],
      probjList:[],

    };
  },
  created() {
    this.getList();
    listProxy().then(response => {
      this.proxyList = response.rows;
    });
    listProzy().then(response => {
      this.prozyList = response.rows;
    });
    listPronj().then(response => {
      this.pronjList = response.rows;
    });
    listProbj().then(response => {
      this.probjList = response.rows;
    });
  },
  methods: {

    handlelistPronj(value){
      var map = {};
      map.pId = value;
      listPronj(map).then(response => {
        this.pronjList = response.rows;
      });
      this.queryParams.njId = null
      this.queryParams.clId = null
      this.queryParams.zyId = null
    },
    handlelistProzy(value){
      var map = {};
      map.pId = value;
      listProzy(map).then(response => {
        this.prozyList = response.rows;
      });
      this.queryParams.clId = null
      this.queryParams.zyId = null
    },
    handlelistProbj(value){
      var map = {};
      map.pId = value;
      listProbj(map).then(response => {
        this.probjList = response.rows;
      });
      this.queryParams.clId = null
    },

    /** 查询督促管理列表 */
    getList() {
      this.loading = true;
      listProuseryjdc(this.queryParams).then(response => {
        this.pronoticeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userId: null,
        content: null
      };
      this.resetForm("form");
    },

    /** 重置 */
    clearCron() {
      this.queryParams.xyId = null
      this.queryParams.njId = null
      this.queryParams.zyId = null
      this.queryParams.clId = null
      this.handleQuery();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.id = this.queryParams.clId
      this.getList();
    },

    /** 督促按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.form.userId = row.terId
      this.open = true;
      this.title = "督促内容设置";
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
            createDc(this.form).then(response => {
              this.$modal.msgSuccess("督促成功");
              this.open = false;
              this.getList();
            });
          }
      });
    }
  }
};
</script>
